<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="风险等级" prop="cRiskLevel">
        <el-input
          v-model="queryParams.cRiskLevel"
          placeholder="请输入风险等级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属地区id" prop="cRegionId">
        <el-input
          v-model="queryParams.cRegionId"
          placeholder="请输入所属地区id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="潜在因素转隐患概率" prop="cQzyszyh">
        <el-input
          v-model="queryParams.cQzyszyh"
          placeholder="请输入潜在因素转隐患概率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="处置隐患概率" prop="cCzyh">
        <el-input
          v-model="queryParams.cCzyh"
          placeholder="请输入处置隐患概率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="潜在因素转刑事案件概率" prop="cQzyszxs">
        <el-input
          v-model="queryParams.cQzyszxs"
          placeholder="请输入潜在因素转刑事案件概率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="案由信息" prop="cCaseOrigin">
        <el-input
          v-model="queryParams.cCaseOrigin"
          placeholder="请输入案由信息"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="案件分析" prop="cCaseAnalyse">
        <el-input
          v-model="queryParams.cCaseAnalyse"
          placeholder="请输入案件分析"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预警对象" prop="cWarningObject">
        <el-input
          v-model="queryParams.cWarningObject"
          placeholder="请输入预警对象"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="要素感知" prop="cPerception">
        <el-input
          v-model="queryParams.cPerception"
          placeholder="请输入要素感知"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="算法模型" prop="cArithmeticModel">
        <el-input
          v-model="queryParams.cArithmeticModel"
          placeholder="请输入算法模型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预警结果
" prop="cWarningResult">
        <el-input
          v-model="queryParams.cWarningResult"
          placeholder="请输入预警结果
"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:caseInfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:caseInfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:caseInfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:caseInfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="caseInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="民转刑案件id" align="center" prop="cCaseId" />
      <el-table-column label="案件类型
" align="center" prop="cCaseType" />
      <el-table-column label="风险等级" align="center" prop="cRiskLevel" />
      <el-table-column label="案件描述" align="center" prop="cCaseDetail" />
      <el-table-column label="案件图片" align="center" prop="cCaseDetailImg" />
      <el-table-column label="所属地区id" align="center" prop="cRegionId" />
      <el-table-column label="潜在因素转隐患概率" align="center" prop="cQzyszyh" />
      <el-table-column label="处置隐患概率" align="center" prop="cCzyh" />
      <el-table-column label="潜在因素转刑事案件概率" align="center" prop="cQzyszxs" />
      <el-table-column label="案由信息" align="center" prop="cCaseOrigin" />
      <el-table-column label="案件分析" align="center" prop="cCaseAnalyse" />
      <el-table-column label="预警对象" align="center" prop="cWarningObject" />
      <el-table-column label="要素感知" align="center" prop="cPerception" />
      <el-table-column label="算法模型" align="center" prop="cArithmeticModel" />
      <el-table-column label="预警结果
" align="center" prop="cWarningResult" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:caseInfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:caseInfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改民转刑事案件管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="风险等级" prop="cRiskLevel">
          <el-input v-model="form.cRiskLevel" placeholder="请输入风险等级" />
        </el-form-item>
        <el-form-item label="案件描述" prop="cCaseDetail">
          <el-input v-model="form.cCaseDetail" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="案件图片" prop="cCaseDetailImg">
          <el-input v-model="form.cCaseDetailImg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="所属地区id" prop="cRegionId">
          <el-input v-model="form.cRegionId" placeholder="请输入所属地区id" />
        </el-form-item>
        <el-form-item label="潜在因素转隐患概率" prop="cQzyszyh">
          <el-input v-model="form.cQzyszyh" placeholder="请输入潜在因素转隐患概率" />
        </el-form-item>
        <el-form-item label="处置隐患概率" prop="cCzyh">
          <el-input v-model="form.cCzyh" placeholder="请输入处置隐患概率" />
        </el-form-item>
        <el-form-item label="潜在因素转刑事案件概率" prop="cQzyszxs">
          <el-input v-model="form.cQzyszxs" placeholder="请输入潜在因素转刑事案件概率" />
        </el-form-item>
        <el-form-item label="案由信息" prop="cCaseOrigin">
          <el-input v-model="form.cCaseOrigin" placeholder="请输入案由信息" />
        </el-form-item>
        <el-form-item label="案件分析" prop="cCaseAnalyse">
          <el-input v-model="form.cCaseAnalyse" placeholder="请输入案件分析" />
        </el-form-item>
        <el-form-item label="预警对象" prop="cWarningObject">
          <el-input v-model="form.cWarningObject" placeholder="请输入预警对象" />
        </el-form-item>
        <el-form-item label="要素感知" prop="cPerception">
          <el-input v-model="form.cPerception" placeholder="请输入要素感知" />
        </el-form-item>
        <el-form-item label="算法模型" prop="cArithmeticModel">
          <el-input v-model="form.cArithmeticModel" placeholder="请输入算法模型" />
        </el-form-item>
        <el-form-item label="预警结果
" prop="cWarningResult">
          <el-input v-model="form.cWarningResult" placeholder="请输入预警结果
" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCaseInfo, getCaseInfo, delCaseInfo, addCaseInfo, updateCaseInfo } from "@/api/system/caseInfo";

export default {
  name: "CaseInfo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 民转刑事案件管理表格数据
      caseInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        cCaseType: null,
        cRiskLevel: null,
        cCaseDetail: null,
        cCaseDetailImg: null,
        cRegionId: null,
        cQzyszyh: null,
        cCzyh: null,
        cQzyszxs: null,
        cCaseOrigin: null,
        cCaseAnalyse: null,
        cWarningObject: null,
        cPerception: null,
        cArithmeticModel: null,
        cWarningResult: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询民转刑事案件管理列表 */
    getList() {
      this.loading = true;
      listCaseInfo(this.queryParams).then(response => {
        this.caseInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        cCaseId: null,
        cCaseType: null,
        cRiskLevel: null,
        cCaseDetail: null,
        cCaseDetailImg: null,
        cRegionId: null,
        cQzyszyh: null,
        cCzyh: null,
        cQzyszxs: null,
        cCaseOrigin: null,
        cCaseAnalyse: null,
        cWarningObject: null,
        cPerception: null,
        cArithmeticModel: null,
        cWarningResult: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.cCaseId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加民转刑事案件管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const cCaseId = row.cCaseId || this.ids
      getCaseInfo(cCaseId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改民转刑事案件管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.cCaseId != null) {
            updateCaseInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCaseInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const cCaseIds = row.cCaseId || this.ids;
      this.$modal.confirm('是否确认删除民转刑事案件管理编号为"' + cCaseIds + '"的数据项？').then(function() {
        return delCaseInfo(cCaseIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/caseInfo/export', {
        ...this.queryParams
      }, `caseInfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
